package Model
{
	import SharedCloud.SyncedObject;
	
	import mx.collections.ArrayCollection;
	import mx.events.CollectionEvent;
	
	[Bindable]
	public class Task extends SyncedObject
	{
		public var title:String = "";		
		public var isAttached:Boolean = true;
		public var x:int = 0;
		public var y:int = 0;
		
		public var estimateHistory:ArrayCollection = new ArrayCollection();
		
		public function set LastTimingAtom(val:TimingAtom):void { }
		public function get LastTimingAtom():TimingAtom
		{
			if(estimateHistory.length == 0) 
				return null;
			return estimateHistory[estimateHistory.length - 1];			
		}
		
		public function set EstimateHistoryHTML(val:String):void {}
		public function get EstimateHistoryHTML():String
		{
			var ret:String = "";
			for(var i:int = 0; i<estimateHistory.length; i++)
			{
				var atom:TimingAtom = estimateHistory[i] as TimingAtom;
				if(atom.isActual)
					ret += "<b>"+String(atom.quantity)+"</b>";
				else
					ret += "<i>"+String(atom.quantity)+"</i>";
				ret += " ";
			}
			return ret;
		}
		
		public function set Color(val:uint):void {}
		public function get Color():uint
		{
			if(LastTimingAtom && LastTimingAtom.isActual)
				return 0xABE1BC;
			else
				return 0xffffcc;
		}
		
		public function Task()
		{
			super();
			estimateHistory.addEventListener(CollectionEvent.COLLECTION_CHANGE, listChangeHandler);
		}
		
		private function listChangeHandler(evt:CollectionEvent):void
		{
			//send blank data to force databinding
			LastTimingAtom = null;
			EstimateHistoryHTML = "";
			Color = 0;
		}
	}
}